package com.iwuke.dance.wallet;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.google.android.material.card.MaterialCardView;
import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.gadget_view.TitleBarView;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;
import com.iwuke.dance.wallet.adapter.AddBandCardAdapter;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/10/14
 * 添加银行卡
 */
public class AddBandCardActivity extends BaseActivity implements View.OnClickListener {

    private TitleBarView title_bar;
    private EditText et_search_box;
    private ImageView img_search;
    private ImageView img_cancel;
    private RecyclerView recycler_view;
    private MaterialCardView material_card_view;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent) {
        BaseActivity.setConnect(AddBandCardActivity.this, networkEvent, title_bar);

    }

    @Override
    protected int getView() {
        return R.layout.activity_add_band_card;
    }

    @Override
    protected void init(View mView) {

        title_bar = findViewById(R.id.title_bar);

        //搜索框
        et_search_box = findViewById(R.id.et_search_box);
        //搜索按钮
        img_search = findViewById(R.id.img_search);
        //取消搜索
        img_cancel = findViewById(R.id.img_cancel);
        //背景阴影
        material_card_view = findViewById(R.id.material_card_view);
        //列表
        recycler_view = findViewById(R.id.recycler_view);



        title_bar.setTitleText("添加银行卡");
        title_bar.setLeftOnClick(this);
        //搜索按钮
        img_search.setOnClickListener(this);
        //取消搜索
        img_cancel.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        et_search_box.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void afterTextChanged(Editable s) {
                //取消搜索
                // 根据输入框是否有文本来显示或隐藏“取消”（清除）按钮
                if (s.length() > 0) {
                    // 有内容时显示清除按钮
                    img_cancel.setVisibility(View.VISIBLE);
                    //背景阴影
                    material_card_view.setVisibility(View.GONE);
                } else {
                    // 无内容时隐藏清除按钮
                    img_cancel.setVisibility(View.GONE);
                    //背景阴影
                    material_card_view.setVisibility(View.VISIBLE);
                }
            }
        });

        List<String> lists = new ArrayList<>();
        lists.add("建设银行");
        setLinearLayoutManager(this,recycler_view);
        AddBandCardAdapter adapter = new AddBandCardAdapter(this, R.layout.adapter_add_band_card, lists);
        recycler_view.setAdapter(adapter);

    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){
            finish();
        }else if (v.getId()==R.id.img_search){//搜索按钮


        }else if (v.getId()==R.id.img_cancel){//取消搜索
            et_search_box.setText("");
        }
    }
}
